package cn.sinata.wanglin.neighbor.fragment;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.drawable.ProgressBarDrawable;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import com.xilada.xldutils.fragment.BaseLazyFragment;
import com.xilada.xldutils.view.ZoomableDraweeView;

import cn.sinata.wanglin.R;

/**
 *
 * Created by liaoxiang on 16/12/16.
 */

public class ShowImageFragment extends BaseLazyFragment{

    public static ShowImageFragment getInstance(String url){
        ShowImageFragment fragment = new ShowImageFragment();
        Bundle bundle = new Bundle();
        bundle.putString("url",url);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.framgent_show_image_layout;
    }

    @Override
    protected void onFirstVisibleToUser() {
        String url;

        if (getArguments()!=null){
            url = getArguments().getString("url");
        }else {
            url = "";
        }

        //noinspection SpellCheckingInspection
        ZoomableDraweeView zoomableDraweeView = mHolder.bind(R.id.zoomDrawee);
        GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources())
                .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                .setProgressBarImage(new ProgressBarDrawable())
                .build();
        Uri uri = Uri.parse(url);
        DraweeController ctrl = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setTapToRetryEnabled(true)
                .build();

        zoomableDraweeView.setHierarchy(hierarchy);
        zoomableDraweeView.setController(ctrl);
        //不设置监听触发不了放大缩小，没看源码为什么
        zoomableDraweeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    protected void onVisibleToUser() {

    }

    @Override
    protected void onInvisibleToUser() {

    }
}
